<template>
	<view class="m-bg-c">
		<view class="m-card">
			<view class="u-p-l-10 u-p-r-10">
				<u--form labelPosition="left" :labelWidth="100" :model="fromData" ref="uForm" errorType="toast">
					<u-form-item :required="true" label="楼盘名称:" prop="properties_name">
						<view class="input u-rela">
							<u-search shape="square" :clearabled="false" height="64" :showAction="false"
								v-model="fromData.properties_name" inputAlign="right" bgColor="#eee" placeholder="请输入"
								@focus="getzhidao" @change="$u.debounce(getzhidao, 500)" @blur="loupanShow = false">
							</u-search>
							<view class="boxinput-y" v-show="loupanShow">
								<view v-if="loupanList.length > 0" style="border-top: 2rpx solid #dadbde;">
									<view class="u-p-t-10 u-p-b-10"
										style="text-align: center; border-bottom: 2rpx solid #dadbde;"
										v-for="(item, index) in loupanList" :key="index" @click="getmieng(item, index)">
										{{ item.name }}
									</view>
								</view>
								<view class="u-m-t-30" v-else>暂时没有搜索到该楼盘，内当家会尽快与你联系</view>
							</view>
						</view>
					</u-form-item>
					<u-form-item :required="true" label="居住楼层:" prop="floor">
						<view class="input">
							<u-search shape="square" searchIcon=" " :clearabled="false" height="64" :showAction="false"
								v-model="fromData.floor" inputAlign="right" bgColor="#eee" placeholder="请输入"></u-search>
						</view>
					</u-form-item>
					<u-form-item :required="true" label="居住房号:" prop="roomnumber">
						<view class="input">
							<u-search shape="square" searchIcon=" " :clearabled="false" height="64" :showAction="false"
								v-model="fromData.roomnumber" inputAlign="right" bgColor="#eee" placeholder="请输入">
							</u-search>
						</view>
					</u-form-item>
					<u-form-item label="联系电话" prop="mobile" required>
						<u-search shape="square" searchIcon=" " maxlength="11" :clearabled="false" :showAction="false"
							v-model="fromData.mobile" inputAlign="right" bgColor="#eee" placeholder="请输入联系方式">
						</u-search>
					</u-form-item>
					<u-form-item :required="true" label="出售价格:" prop="price">
						<view class="u-flex u-flex-items-center">
							<view class="boxhh u-flex u-flex-items-center">
								<u--input type="number" inputAlign="right" v-model="fromData.price"
									placeholder="请输入总价(单位万元)" border="none"></u--input>
							</view>
							<text class="u-m-l-10">万</text>
							<!-- <text class="u-font-25 u-m-l-20 m-c-9"
								v-if="guidance_price">指导价格：{{guidance_price}}/㎡</text>
							<text class="u-font-25 u-m-l-20" v-else>暂无</text> -->
						</view>
					</u-form-item>
					<u-form-item label="指导价格:">
						<text class="u-font-25 u-m-l-20 m-c-9" v-if="guidance_price">{{ guidance_price }}元/㎡</text>
						<text class="u-font-25 u-m-l-20" v-else>暂无</text>
					</u-form-item>
					<u-form-item :required="true" label="房屋面积:" prop="area">
						<view class="input">
							<u-search shape="square" searchIcon=" " :clearabled="false" height="64" :showAction="false"
								v-model="fromData.area" inputAlign="right" bgColor="#eee" placeholder="请输入"></u-search>
						</view>
					</u-form-item>
					<u-form-item :required="true" label="房屋年限:" prop="year">
						<view class="input">
							<u-search shape="square" searchIcon=" " :clearabled="false" height="64" :showAction="false"
								v-model="fromData.year" inputAlign="right" bgColor="#eee" placeholder="请输入"></u-search>
						</view>
					</u-form-item>
					<u-form-item :required="true" label="房屋朝向:" prop="orientation">
						<view class="u-flex u-flex-items-center">
							<view class="v-input" @click="show = true">
								<u-search shape="square" searchIcon=" " :clearabled="false" height="64"
									:showAction="false" v-model="fromData.orientation" disabled inputAlign="right"
									bgColor="#eee" placeholder="请选择"></u-search>
							</view>
							<text class="u-font-25 u-m-l-32 m-c-9">阳台朝向为主</text>
						</view>
					</u-form-item>
					<u-form-item :required="true" label="房屋户型:" prop="bedroom">
						<view class="u-flex u-flex-items-center">
							<view class="u-flex u-flex-items-center">
								<view class="boxhuxing u-flex u-flex-items-center">
									<u--input type="number" inputAlign="center" v-model="fromData.bedroom"
										placeholder=" " border="none"></u--input>
								</view>
								<text class="u-font-25 u-m-l-5 m-c-9">室</text>
							</view>
							<view class="u-flex u-flex-items-center">
								<view class="boxhuxing u-flex u-flex-items-center">
									<u--input type="number" inputAlign="center" v-model="fromData.room" placeholder=" "
										border="none"></u--input>
								</view>
								<text class="u-font-25 u-m-l-5 m-c-9">厅</text>
							</view>
							<view class="u-flex u-flex-items-center">
								<view class="boxhuxing u-flex u-flex-items-center">
									<u--input type="number" inputAlign="center" v-model="fromData.toilet"
										placeholder=" " border="none"></u--input>
								</view>
								<text class="u-font-25 u-m-l-5 m-c-9">卫</text>
							</view>
							<view class="u-flex u-flex-items-center">
								<view class="boxhuxing u-flex u-flex-items-center">
									<u--input type="number" inputAlign="center" v-model="fromData.kitchen"
										placeholder=" " border="none"></u--input>
								</view>
								<text class="u-font-25 u-m-l-5 m-c-9">厨</text>
							</view>
						</view>
					</u-form-item>
					<u-form-item :required="true" label="房屋地址:" prop="province">
						<view class="u-flex u-flex-items-center u-flex-wrap">
							<view @click="pick('province')">
								<view class="boxdizhi" :class="fromData.province ? '' : 'ce1'">
									{{ fromData.province || '请选择' }}
								</view>
							</view>
							<view class="u-m-l-20" @click="pick('city')">
								<view class="boxdizhi">
									<text :class="fromData.city ? '' : 'ce1'">{{ fromData.city || '请选择' }}</text>
								</view>
							</view>
							<view class="u-m-l-20" @click="pick('areaname')">
								<view class="boxdizhi">
									<text
										:class="fromData.areaname ? '' : 'ce1'">{{ fromData.areaname || '请选择' }}</text>
								</view>
							</view>
						</view>
					</u-form-item>
					<u-form-item label="房屋图片:" :required="true" prop="tupian"></u-form-item>
					<u-upload width="194rpx" height="194rpx" :fileList="fromData.images" @afterRead="afterRead"
						@delete="deletePic" multiple :previewFullImage="true">
						<view class="boxup m-flex-y u-flex-items-center u-flex-center">
							<u-icon name="photo" size="40" color="#ddd"></u-icon>
							<view class="u-m-t-10">上传图片</view>
						</view>
					</u-upload>
					<view class="m-c-9 u-m-b-30 u-flex u-flex-end">至少上传5张图片</view>
					<u-form-item label="是否带装修:" :required="true">
						<view class="">
							<radio-group @change="radioChange0"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist1"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :checked="index === current0" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="房屋状态:" :required="true">
						<view>
							<radio-group @change="radioChange1"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist2"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :checked="index === current1" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="如何看房:" :required="true">
						<view>
							<radio-group @change="radioChange2"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist3"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :checked="index === current2" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="贷款情况:" :required="true">
						<view>
							<radio-group @change="radioChange3"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist4"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :checked="index === current3" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="剩余贷款:" v-if="current3 === 1">
						<view class="input">
							<u-search shape="square" searchIcon=" " :clearabled="false" height="64" :showAction="false"
								v-model="fromData.loanmoney" inputAlign="right" bgColor="#eee" placeholder="请输入">
							</u-search>
						</view>
					</u-form-item>
					<u-form-item label="房产证满5年:" :required="true">
						<view>
							<radio-group @change="radioChange4"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist5"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :disabled="item.disabled"
											:checked="index === current4" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="房产证满2年:" :required="true">
						<view>
							<radio-group @change="radioChange5"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist6"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :disabled="item.disabled"
											:checked="index === current5" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="是否唯一住房:" :required="true">
						<view>
							<radio-group @change="radioChange6"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist7"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :checked="index === current6" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="房屋性质:" :required="true">
						<view>
							<radio-group @change="radioChange7"
								class="u-flex u-flex-wrap u-flex-between u-flex-items-center">
								<label class="u-flex u-m-t-10 w_40" v-for="(item, index) in radiolist8"
									:key="item.name">
									<view>
										<radio :value="item.name" color="#DAAF7F" :checked="index === current7" />
									</view>
									<view>{{ item.name }}</view>
								</label>
							</radio-group>
						</view>
					</u-form-item>
					<u-form-item label="是否有电梯:" :required="true">
						<view class="u-flex u-flex-items-center">
							<view class="v-input" @click="showa = true">
								<u-search shape="square" searchIcon=" " disabled :clearabled="false" height="64"
									:showAction="false" v-model="fromData.elevator" inputAlign="right" bgColor="#eee"
									placeholder="请选择"></u-search>
							</view>
						</view>
					</u-form-item>
					<u-form-item label="业主描述:" :required="true">
						<view class="boxtext">
							<u--textarea v-model="fromData.mentality" placeholder="请输入内容"></u--textarea>
						</view>
					</u-form-item>
				</u--form>
				<!-- 地图 -->
				<map style="width:600rpx; height: 250rpx;margin:30rpx auto;"
					:latitude="fromData.lat ? fromData.lat : latitude"
					:longitude="fromData.lon ? fromData.lon : longitude" @tap="tap" :enable-zoom="false"
					:enable-scroll="false" scale="14"></map>
				<view class="tijiao" @click="submit">下一步</view>
			</view>
		</view>
		<!-- 房屋朝向 -->
		<u-picker :show="show" :columns="columns" @cancel="show = false" @confirm="confirm" @close="close"
			:closeOnClickOverlay="true"></u-picker>
		<!-- 房屋地址 -->
		<!-- 电梯 -->
		<u-picker :show="showa" :columns="columnsa" @cancel="showa = false" @confirm="confirma" @close="close"
			:closeOnClickOverlay="true"></u-picker>
		<!-- 省市区 -->
		<u-picker :show="showArea" :columns="sheng" @cancel="showArea = false" keyName="name" @confirm="confirmArea"
			@close="close" :closeOnClickOverlay="true"></u-picker>
	</view>
</template>

<script>
	import uploadImage from '@/js_sdk/yushijie-ossutil/ossutil/uploadFile.js';
	export default {
		data() {
			return {
				item: null,
				showArea: false,
				fileList1: [],
				show: false,
				columns: [
					['东', '东北', '东南', '南', '西', '西北', '西南', '北']
				],
				showa: false,
				columnsa: [
					['无电梯', '一部', '两部', '三部', '四部']
				],
				showb: false,
				showc: false,
				showSex: false,
				fromData: {
					properties_name: '', //楼盘名称
					floor: '', //居住楼层
					roomnumber: '', //居住房号
					price: '', //出售价格
					area: '', //房屋面积
					orientation: '', //房屋朝向
					bedroom: '', //房屋户型(室)
					room: '', //房屋户型(厅)
					toilet: '', //房屋户型(卫)
					kitchen: '', //房屋户型(厨房)
					loanmoney: '', //欠款金额
					province: '', //省
					city: '', //房屋地址城市
					areaname: '', //房屋地址区
					images: [], //图片
					elevator: '', //电梯几部
					style: '', //装修
					situation: '', //状态
					lookroom: '', //看房
					is_loan: '', // 贷款情况
					cardyear5_switch: '', //五年
					cardyear2_switch: '', //两年
					only_switch: '', // 唯一
					roomnature: '', //性质
					lat: '',
					lon: '',
					address: '',
					fangchanzheng_id: '',
					shiming_id: '',
					mentality: '', // 业主描述
					year: '', //房子年限
					mobile: '' //电话
				},
				elevator: null,
				radiolist1: [{
						name: '毛坯',
						disabled: false
					},
					{
						name: '豪华装修',
						disabled: false
					},
					{
						name: '精简装修',
						disabled: false
					}
				],
				radiolist2: [{
						name: '自行居住',
						disabled: false
					},
					{
						name: '租户居住',
						disabled: false
					},
					{
						name: '房屋空置',
						disabled: false
					}
				],
				radiolist3: [{
						name: '随时看房',
						disabled: false
					},
					{
						name: '提前通知',
						disabled: false
					}
				],
				radiolist4: [{
						name: '没贷款',
						disabled: false
					},
					{
						name: '还贷中',
						disabled: false
					}
				],
				radiolist5: [{
						name: '已满五年',
						disabled: false
					},
					{
						name: '未满五年',
						disabled: false
					}
				],
				radiolist6: [{
						name: '已满两年',
						disabled: false
					},
					{
						name: '未满两年',
						disabled: false
					}
				],
				radiolist7: [{
						name: '唯一住房',
						disabled: false
					},
					{
						name: '非唯一住房',
						disabled: false
					}
				],
				radiolist8: [{
						name: '商品房',
						disabled: false
					},
					{
						name: '别墅',
						disabled: false
					},
					{
						name: '公寓',
						disabled: false
					},
					{
						name: '商铺',
						disabled: false
					},
					{
						name: '写字楼',
						disabled: false
					}
				],
				radiovalue4: '',
				radiovalue5: '',
				latitude: null,
				longitude: null,
				current0: null,
				current1: null,
				current2: null,
				current3: null,
				current4: null,
				current5: null,
				current6: null,
				current7: null,
				loading_show_status: false,
				fangzi_id: null,
				obj: {},
				sheng: [],
				key: 'province',
				loupanList: [],
				distinguish: 1,
				guidance_price: '',
				loupanShow: false,
				type: 0,
				ida: null,
				citydata: [],
				jiekou: 0,
				fen:{
					FZ:'',
					ZM:''
				},
				rules: {
					properties_name: [{
						required: true,
						message: '请输入楼盘名称',
						trigger: ['blur', 'change']
					}],
					orientation: [{
						required: true,
						message: '请选择房屋朝向',
						trigger: ['blur', 'change']
					}],
					floor: [{
						validator: (rule, value, callback) => {
							return /^[1-9]\d*$/.test(value);
						},
						message: '请输入居住楼层',
						trigger: ['blur', 'change']
					}],
					tupian: [{
						validator: (rule, value, callback) => {
							return this.fromData.images.length >= 5;
						},
						message: '请至少上传5张图片',
						trigger: ['blur', 'change']
					}],
					mobile: [{
						validator: (rule, value, callback) => {
							return uni.$u.test.mobile(value);
						},
						message: '请输入客户正确手机号',
						trigger: ['blur', 'change']
					}],
					roomnumber: [{
						validator: (rule, value, callback) => {
							return /^\d{1,4}(-\d{1,4})?$/.test(value);
						},
						message: '请输入居住楼层的房号',
						trigger: ['blur', 'change']
					}],
					year: [{
						required: true,
						message: '请输入房屋年限',
						trigger: ['blur', 'change']
					}],
					price: [{
						validator: (rule, value, callback) => {
							return /^\d+(\.\d+)?$/.test(value);
						},
						message: '请输入出售价格',
						trigger: ['blur', 'change']
					}],
					area: [{
						validator: (rule, value, callback) => {
							return /^\d+(\.\d+)?$/.test(value);
						},
						message: '请输入房屋面积',
						trigger: ['blur', 'change']
					}],
					bedroom: [{
						validator: (rule, value, callback) => {
							return /^[1-9]\d*$/.test(value);
						},
						message: '请输入房屋户型',
						trigger: ['blur', 'change']
					}],
					province: [{
						validator: (rule, value, callback) => {
							return this.fromData.areaname !== '';
						},
						message: '请选择房屋地址',
						trigger: ['blur', 'change']
					}],
				}
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		async onLoad(e) {
			// #ifdef MP-WEIXIN
			uni.hideShareMenu();
			// #endif
			if (e.type) {
				this.type = +e.type;
			}
			if (e.item) {
				let fen = JSON.parse(e.item);
				this.fen = fen;
				this.fromData.fangchanzheng_id = fen.FZ;
				this.fromData.shiming_id = fen.ZM;
			}
			let that = this;
			uni.getLocation({
				type: 'gcj02',
				success: function(res) {
					that.latitude = res.latitude;
					that.longitude = res.longitude;
				}
			});
			await this.getsheng();
			if (e.id) {
				uni.setNavigationBarTitle({
					title: '修改房子资料'
				});
				this.jiekou = +e.id;
				let res = await this.require('gettowhouse', {
					id: +e.id
				});
				if (res) {
					await this.getzhidao();
					this.fromData = res;
					this.fromData.price = (res.price * 1) / 10000;
					this.distinguish = 2;
					this.loupanList.map((p, i) => {
						if (p.id == res.fczj_properties_id) {
							this.guidance_price = p.guidance_price;
						}
					});
					let img = res.images.split(',');
					this.fromData.images = []
					for(var i=0;i<img.length;i++){
						this.fromData.images.push({
							url: img[i]
						})
					}
					this.fromData.lat = +res.lat;
					this.fromData.lon = +res.lon;
					this.current0 = res.style == '毛坯' ? 0 : res.style == '豪华装修' ? 1 : 2;
					this.current1 = res.situation == '自行居住' ? 0 : res.situation == '租户居住' ? 1 : 2;
					this.current2 = res.lookroom == '随时看房' ? 0 : 1;
					this.current3 = res.is_loan == 0 ? 0 : 1;
					this.current4 = res.cardyear5_switch == 1 ? 0 : 1;
					this.current5 = res.cardyear2_switch == 1 ? 0 : 1;
					this.current6 = res.only_switch;
					this.current7 =
						res.roomnature == '商品房' ? 0 : res.roomnature == '别墅' ? 1 : res.roomnature == '公寓' ? 2 : res
						.roomnature == '商铺' ? 3 : res.roomnature == '写字楼' ? 4 : '';
					this.fromData.elevator = res.elevator == 0 ? '无电梯' : res.elevator == 1 ? '一部' : res.elevator == 2 ?
						'两部' : res.elevator == 3 ? '三部' : '四部';
					this.elevator = res.elevator == '无电梯' ? 0 : res.elevator == '一部' ? 1 : res.elevator == '两部' ?
						2 : res.elevator == '三部' ? 3 :  res.elevator == '四部' ? 4 : null;
					this.loupanShow = false;
				}
			}
		},
		watch: {
			item(newVal) {
				if (newVal) {
					this.fromData.properties_name = newVal.name;
					this.fromData.lat = newVal.lat;
					this.fromData.lon = newVal.lon;
					this.fromData.address = newVal.address;
					this.ida = newVal.id;
					this.guidance_price = newVal.guidance_price;
				} else {
					this.fromData.properties_name = '';
					this.fromData.lat = '';
					this.fromData.lon = '';
					this.fromData.address = '';
					this.ida = '';
					this.guidance_price = '';
				}
			},
			'fromData.properties_name':{
				handler(newda,oldda){
					if(oldda.length){
						this.distinguish = 1;
					}
				}
			}
		},
		methods: {
			// 获取全部省市区
			async getsheng() {
				let res = await this.require('cityall');
				if (res) {
					this.citydata = res;
				}
			},
			tap() {
				let that = this;
				if (this.fromData.lat && this.fromData.address) return;
				uni.chooseLocation({
					success: function(res) {
						that.fromData.lat = res.latitude;
						that.fromData.lon = res.longitude;
						that.fromData.address = res.address;
					}
				});
			},
			getmieng(item, index) {
				this.loupanShow = false;
				this.item = item;
			},
			//二手房指导价
			async getzhidao() {
				if (this.fromData.properties_name === (this.item && this.item.name)) {
					return;
				}
				if(this.distinguish == 2){
					return;
				}
				this.item = null;
				let option = {
					p: this.params.p,
					pnum: 99,
					loupanleixing: '二手房'
				};
				if (this.fromData.properties_name) {
					option.keywords = this.fromData.properties_name;
				}
				let res = await this.require('propertieslist', option);
				if (res) {
					this.loupanList = res;
					this.loupanShow = true;
				}
			},
			async pick(key) {
				this.key = key;
				await this.getsheng();
				switch (key) {
					case 'province':
						this.sheng = [this.citydata];
						break;
					case 'city':
						if (!this.fromData.province) {
							return this.$u.toast('请依次选择省市区');
						}
						this.sheng = [this.citydata[this.obj.province_idx].child];
						break;
					case 'areaname':
						if (!this.fromData.city) {
							return this.$u.toast('请依次选择省市区');
						}
						this.sheng = [this.citydata[this.obj.province_idx].child[this.obj.city_idx].child];
						break;
					default:
						break;
				}
				this.showArea = true;
			},
			radioChange0(evt) {
				for (let i = 0; i < this.radiolist1.length; i++) {
					if (this.radiolist1[i].name === evt.detail.value) {
						this.current0 = i;
						break;
					}
				}
			},
			radioChange1(evt) {
				for (let i = 0; i < this.radiolist2.length; i++) {
					if (this.radiolist2[i].name === evt.detail.value) {
						this.current1 = i;
						break;
					}
				}
			},
			radioChange2(evt) {
				for (let i = 0; i < this.radiolist3.length; i++) {
					if (this.radiolist3[i].name === evt.detail.value) {
						this.current2 = i;
						break;
					}
				}
			},
			radioChange3(evt) {
				for (let i = 0; i < this.radiolist4.length; i++) {
					if (this.radiolist4[i].name === evt.detail.value) {
						this.current3 = i;
						break;
					}
				}
			},
			radioChange4(evt) {
				for (let i = 0; i < this.radiolist5.length; i++) {
					if (this.radiolist5[i].name === evt.detail.value) {
						this.current4 = i;
						this.radiovalue4 = evt.detail.value;
						break;
					}
				}
				for (let i = 0; i < this.radiolist6.length; i++) {
					this.radiolist6[i].disabled = this.current4 === 0;
				}
				if (this.current4 === 0) {
					this.current5 = null;
				}
			},
			radioChange5(evt) {
				for (let i = 0; i < this.radiolist6.length; i++) {
					if (this.radiolist6[i].name === evt.detail.value) {
						this.current5 = i;
						this.radiovalue5 = evt.detail.value;
						// this.current4 = 1;
						break;
					}
				}
				for (let i = 0; i < this.radiolist5.length; i++) {
					this.radiolist5[i].disabled = this.current5 === 1;
				}
				if (this.current5 === 1) {
					this.current4 = 1;
				}
			},
			radioChange6(evt) {
				for (let i = 0; i < this.radiolist7.length; i++) {
					if (this.radiolist7[i].name === evt.detail.value) {
						this.current6 = i;
						break;
					}
				}
			},
			radioChange7(evt) {
				for (let i = 0; i < this.radiolist8.length; i++) {
					if (this.radiolist8[i].name === evt.detail.value) {
						this.current7 = i;
						break;
					}
				}
			},
			// 删除图片
			deletePic(event) {
				this.fromData.images.splice(event.index, 1);
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file);
				let fileListLen = this.fromData.images.length;
				lists.map(item => {
					this.fromData.images.push({
						...item,
						status: 'uploading',
						message: '上传中'
					});
				});
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].thumb);
					let item = this.fromData.images[fileListLen];
					this.fromData.images.splice(
						fileListLen,
						1,
						Object.assign(item, {
							status: 'success',
							message: '',
							url: result
						})
					);
					fileListLen++;
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uploadImage(
						url,
						'roomuploads/',
						result => {
							setTimeout(() => {
								resolve(result);
							}, 1000);
						},
						result => {
							//这里写上传失败的代码
							console.log(JSON.stringify(result));
						}
					);
				});
			},
			async submit() {
				let that = this;
				if (!(await this.getMobile())) {
					return;
				}
				this.$refs.uForm
					.validate()
					.then(async res1 => {
						let from = uni.$u.deepClone(that.fromData);
						if (!from.lat) {
							uni.$u.toast('请打开地图选择楼房位置');
							return;
						}
						if (that.current0 == null) {
							uni.$u.toast('请选择装修情况');
							return;
						} else if (that.current1 == null) {
							uni.$u.toast('请选择房屋状态');
							return;
						} else if (that.current2 == null) {
							uni.$u.toast('请选择如何看房');
							return;
						} else if (that.current3 == null) {
							uni.$u.toast('请选择贷款情况');
							return;
						} else if (that.current3 == 1 && !from.loanmoney) {
							uni.$u.toast('请输入剩余贷款');
							return;
						} else if (that.current3 == 1 && !/^\d+(\.\d+)?$/.test(from.loanmoney)) {
							uni.$u.toast('剩余贷款只能填入数字');
							return;
						} else if (that.current4 === null && that.current5 === null) {
							uni.$u.toast('请选择房产证年限');
							return;
						} else if (that.current6 == null) {
							uni.$u.toast('请选择是否是唯一住房');
							return;
						} else if (that.current7 == null) {
							uni.$u.toast('请选择房屋性质');
							return;
						} else if (that.elevator == null) {
							uni.$u.toast('请选择电梯情况');
							return;
						} else if (from.mentality == '') {
							uni.$u.toast('请填写业主描述');
							return;
						}
						for (var i = 0; i < from.images.length; i++) {
							from.images[i] = from.images[i].url;
						}
						from.images = from.images.join(',');
						from.style = that.current0 != null ? that.radiolist1[that.current0].name : '';
						from.situation = that.current1 != null ? that.radiolist2[that.current1].name : '';
						from.lookroom = that.current2 != null ? that.radiolist3[that.current2].name : '';
						from.is_loan = that.current3;
						from.cardyear5_switch = that.current4 == 0 ? 1 : 0;
						from.cardyear2_switch = that.current5 == 0 ? 1 : 0;
						from.only_switch = that.current6 === 0 ? 1 : 0;
						from.roomnature = that.current7 != null ? that.radiolist8[that.current7].name : '';
						from.elevator = that.elevator;
						from.lat = +from.lat;
						from.lon = +from.lon;
						from.room = from.room ? from.room : 0;
						from.toilet = from.toilet ? from.toilet : 0;
						from.kitchen = from.kitchen ? from.kitchen : 0;
						from.loanmoney = from.loanmoney ? from.loanmoney : 0;
						from.price = from.price * 10000;
						from.properties_id = that.ida || '';
						let fangchan = uni.getStorageSync('fangchanzheng') ? JSON.parse(uni.getStorageSync('fangchanzheng')) : '';
						from.fangchanzheng_id = this.fen.FZ ? this.fen.FZ : fangchan.FZ;
						from.shiming_id = this.fen.ZM ? this.fen.ZM : fangchan.ZM;
						let jie = null;
						if (this.jiekou == 0) {
							jie = that.type === 1 ? 'getAddhouse' : 'addtowhouse';
						} else {
							jie = 'revisetowhouse';
							from.properties_id = from.fczj_properties_id; // 楼盘id
						}
						let res22 = await this.require(jie, from);
						if (res22) {
							this.nextNav('/pages/tabbar/mine');
						}
					})
					.catch(errors => {});
			},
			confirm(e) {
				this.fromData.orientation = e.value[0];
				this.show = false;
			},
			confirma(e) {
				this.fromData.elevator = e.value[0];
				this.elevator = e.indexs[0];
				this.showa = false;
			},
			confirmArea(e) {
				this.showArea = false;
				this.obj[this.key] = e.value[0].id;
				this.obj[this.key + '_idx'] = e.indexs[0];
				this.fromData[this.key] = e.value[0].name;
			},
			close() {
				this.showa = false;
				this.show = false;
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			getde(index) {
				this.images.splice(index, 1);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.m-bg-c {
		background: linear-gradient(#0e5642, #0e5642 200rpx, #f2f2f2 200rpx, #f2f2f2 100%);
		padding: 30rpx;
	}

	.boxhuxing {
		width: 68rpx;
		height: 64rpx;
		background-color: #eee;
		border-radius: 5rpx;
	}

	.boxhh {
		background-color: #eee;
		height: 64rpx;
		border-radius: 5rpx;
	}

	.boxinput {
		top: 16px;
		right: 0;
		left: 0;
		text-align: center;
		border-radius: 10rpx;
	}

	.boxinput-y {
		overflow-y: auto;
		height: 600rpx;
		position: absolute;
		left: 0;
		right: 0;
		top: 37px;
		border: 2rpx solid #dadbde;
		padding: 20rpx;
		background-color: #fff;
		z-index: 99999;
		border-radius: 10rpx;
	}

	.boximg {
		width: 148rpx;
		height: 148rpx;
		position: relative;
		z-index: 1;
	}

	.w_40 {
		width: 45%;
	}

	.boxdizhi {
		width: 120rpx;
		height: 64rpx;
		overflow-x: auto;
		line-height: 64rpx;
		text-align: center;
		background-color: #eee;
		border-radius: 4rpx;
	}

	.ce1 {
		color: #cecccc;
	}

	.boxtext {
		border: 2rpx solid #eee;
		border-radius: 5rpx;
	}

	.iconde {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
		z-index: 99;
	}

	.boxup {
		width: 194rpx;
		height: 194rpx;
		background-color: #f8f8f8;
		color: #ddd;
	}

	.input {
		width: 450rpx !important;
	}

	.v-input {
		width: 200rpx !important;
		display: flex;
		align-items: center;
	}

	.y-input {
		width: 200rpx !important;
		display: flex;
		align-items: center;
	}

	.s-input {
		width: 100rpx !important;
		display: flex;
		align-items: center;
		margin-left: 15rpx;
	}

	.t-input {
		width: 100rpx !important;
		display: flex;
		align-items: center;
	}

	.m-c-9 {
		color: #c0c0c0;
	}

	.tijiao {
		width: 300rpx;
		height: 80rpx;
		margin: auto;
		background-color: #0e5543;
		border-radius: 20rpx;
		color: #ffffff;

		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
